// import { AppContext } from "../app.context";

export interface UserInfo {
  account: string;
  avatar: string;
  gender: number;
  nickName: string;
  signature: string; // 签名
  uid: string;
  mark: string;
  openid: string;
  phone: number;
}


export class UserModel {
  private _data = <UserInfo>{};
  private _openid = '';

  constructor() {
    console.log("user mode...");
  }


  public get data(): UserInfo {
    if (!this._data.uid) {
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000
      })
    }
    return this._data;

  }
  public setData(info: UserInfo): void {
    this._data = info;
  }

  public clear(): void {
    wx.getBackgroundAudioManager().pause();
    this._data = {} as UserInfo;
  }

  public get openid(): string {
    if (!this._openid) {
      try {
        this._openid = wx.getStorageSync('openid');
        return this._openid;
      } catch (e) {
        // Do something when catch error
      }
    }
    return this._openid;
  }

}
